<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增物业公司</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="">
        <input type="hidden" name="id"/>
        <div class="layui-form-item">
            <label class="layui-form-label">充值点名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="充值点名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每日限额</label>
            <div class="layui-input-block">
                <input type="text" name="dayRechargeLimit" required lay-verity="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单笔限额</label>
            <div class="layui-input-block">
                <input type="text" name="oneRechargeLimit" required lay-verity="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保证金</label>
            <div class="layui-input-block">
                <input type="text" name="deposit" required lay-verity="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-block">
                <input type="text" name="createTime" disabled autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="update" lay-submit lay-filter="update">保存修改</button>
            </div>
        </div>
    </form>
</div>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/token.js"></script>
<script src="../../js/config.js"></script>

<script>

    //url 传参
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var a = decodeURI(window.location.search);
        var r = a.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if(r!=null)return  unescape(r[2]); return null;
    }

    window.onload = function(){
        $("input[name='id']").val(GetQueryString("id"));
        $("input[name='name']").val(GetQueryString("name"));
        var dayRecharge = GetQueryString("dayRechargeLimit");
        if (dayRecharge=="null" || dayRecharge==null || dayRecharge=="undefined" || dayRecharge == "") {
            $("input[name='dayRechargeLimit']").val("0");
        }else {
            $("input[name='dayRechargeLimit']").val(GetQueryString("dayRechargeLimit"));
        }
        var oneRecharge = GetQueryString("oneRechargeLimit");
        if (oneRecharge=="null" || oneRecharge==null || oneRecharge=="undefined" || oneRecharge == "") {
            $("input[name='oneRechargeLimit']").val("0");
        }else {
            $("input[name='oneRechargeLimit']").val(GetQueryString("oneRechargeLimit"));
        }
        var deposit = GetQueryString("deposit");
        if (deposit=="null" || deposit==null || deposit=="undefined" || deposit == "") {
            $("input[name='deposit']").val("0");
        }else {
            $("input[name='deposit']").val(GetQueryString("deposit"));
        }

        var createTime = GetQueryString("createTime");
        $("input[name='createTime']").val(GetQueryString("createTime"));
    }

    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //添加操作
        form.on('submit(update)',function(data){
            var moneyTest = /^[1-9]\d*$/;
            if(data.field.dayRechargeLimit==""){
                layer.msg('每日限额不能为空');
                return false;
            }
            if(!moneyTest.test(data.field.dayRechargeLimit)){
                layer.msg('每日限额数值不合法，请输入大于0的整数');
                return false;
            }
            if(data.field.oneRechargeLimit==""){
                layer.msg('单笔限额不能为空');
                return false;
            }
            if(!moneyTest.test(data.field.oneRechargeLimit)){
                layer.msg('单笔额数值不合法，请输入大于0的整数');
                return false;
            }
            if(data.field.deposit==""){
                layer.msg('保证金不能为空');
                return false;
            }
            if(!moneyTest.test(data.field.deposit)){
                layer.msg('保证金数值不合法，请输入大于0的整数');
                return false;
            }

            $.ajax({
                url: HOST+"recharge/station/update"
                , type: "POST"
                , contentType: 'application/json'
                , data: JSON.stringify(data.field)
                , success: function (data) {
                    if (data.code == 500) {
                        layer.msg(data.msg)
                    }else if(data.code==0) {
                        layer.msg('修改成功');
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 2000);
                    }
                }
                ,error:function () {
                    console.log("ajax error");
                }
            })
            return false;
        });
    });
</script>
</body>
</html>